package com.IT.service;

import com.IT.dao.CheckGroupDao;
import com.IT.entity.PageResult;
import com.IT.entity.QueryPageBean;
import com.IT.pojo.CheckGroup;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CheckGroupServiceImpl implements CheckGroupService {

    @Autowired
    CheckGroupDao checkGroupDao;
    /*
    /步骤:1.添加检查组的基本信息(主键回显(selectKey))
          2.维护检查组与检查项中间表的关系
     */

    @Override
    @Transactional
    public void add(CheckGroup checkGroup, Integer[] checkitemIds) {
        //1.添加检查组的基本信息(主键回显(selectKey))
        checkGroupDao.add(checkGroup);
        // 2.维护检查组与检查项中间表的关系
        if (checkGroup.getId() != null && checkitemIds != null && checkitemIds.length > 0) {
            for (Integer checkitemId : checkitemIds) {
                checkGroupDao.set(checkGroup.getId(),checkitemId);
            }
        }

    }

    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {
        //1.开始分页
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //2.条件查询
        Page<CheckGroup> page=checkGroupDao.findByCondition(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),page);
    }
}
